﻿using System;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using WebApplication2.DAL;
using WebApplication2.Models;

namespace WebApplication2.Controllers
{
    public class IndexController : Controller
    {
        AccountContext cont = new AccountContext();

        // GET: Index
        public ActionResult Index()
        {
            return View(cont.SysUsers);
        }

        public ActionResult Details(int id)
        {
            SysUser sysUser = cont.SysUsers.Find(id);
            return View(sysUser);
        }

        [HttpPost]
        public ActionResult Create(SysUser sysUser)
        {
            cont.SysUsers.Add(sysUser);
            cont.SaveChanges();
            return Redirect("Index");
        }

        public ActionResult Create()
        {
            return View();
        }

        public ActionResult Update(int id)
        {
            SysUser sysUser = cont.SysUsers.Find(id);
            return View("Update", sysUser);
        }

        [HttpPost]
        public ActionResult Update(SysUser sysUser)
        {
            cont.Entry(sysUser).State = EntityState.Modified;

            cont.SaveChanges();

            return RedirectToAction("Index");
        }

        public ActionResult delete(int id)
        {
            SysUser sysUser = cont.SysUsers.Find(id);
            cont.SysUsers.Remove(sysUser);
            cont.SaveChanges();
            return RedirectToAction("Index");
        }
    }

}